package com.jwds.digital.bios.business.integration.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.jwds.digital.bios.business.core.enums.WorkTypeEnum;
import com.jwds.digital.bios.business.core.infrastructure.dto.external.JobScheduleInfoDTO;
import com.jwds.digital.bios.business.core.infrastructure.entity.dispatch.DispatchReceivingMaterials;
import com.jwds.digital.bios.business.core.infrastructure.entity.external.OperativePlan;
import com.jwds.digital.bios.business.core.infrastructure.mapper.dispatch.DispatchReceivingMaterialsMapper;
import com.jwds.digital.bios.business.core.infrastructure.mapper.external.OperativePlanMapper;
import com.jwds.digital.bios.business.integration.service.ExternalDataProcess;
import com.jwds.tdc.framework.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 收料作业计划信息
 * @Author lizhiming
 */
@Service
public class L32BC06 implements ExternalDataProcess {

    @Autowired
    DispatchReceivingMaterialsMapper dispatchReceivingMaterialsMapper;

    @Autowired
    OperativePlanMapper operativePlanMapper;

    @Override
    public String getMessageId() {
        return this.getClass().getSimpleName();
    }

    @Override
    public void addProcess(Object dataObj) throws BusinessException {
        JobScheduleInfoDTO jobScheduleInfoDTO = BeanUtil.toBean(dataObj, JobScheduleInfoDTO.class);
        //todo 入库
        //判断是否为受料
        if (jobScheduleInfoDTO.getWorkType().equals(WorkTypeEnum.RECEIVING.getCode())) {
            //储存到料场收料调度
            DispatchReceivingMaterials readingTaskData = new DispatchReceivingMaterials();
            BeanUtil.copyProperties(jobScheduleInfoDTO, readingTaskData);
            dispatchReceivingMaterialsMapper.insert(readingTaskData);
        }
        // 入库
        OperativePlan operativePlan = new OperativePlan();
        BeanUtil.copyProperties(jobScheduleInfoDTO, operativePlan);
        operativePlanMapper.insert(operativePlan);
    }

    @Override
    public void updateProcess(Object dataObj) throws BusinessException {
        JobScheduleInfoDTO jobScheduleInfoDTO = BeanUtil.toBean(dataObj, JobScheduleInfoDTO.class);
        //todo 更新
    }

    @Override
    public void deleteProcess(Object dataObj) throws BusinessException {
        JobScheduleInfoDTO jobScheduleInfoDTO = BeanUtil.toBean(dataObj, JobScheduleInfoDTO.class);
        //todo 删除
    }
}
